<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>课程信息录入</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <link rel="stylesheet" href="css/left.css">
    <script src="js/jquery.min.js"></script>
    <script src="js/bootstrap.min.js"></script>

    <script src="js/vue.js"></script>
    <script>
        $(function () {
            var href = location.href;
            var classId = 0;
            if(href.indexOf("?")>0){
                var id = href.split("?")[1];
                classId = id.split("=")[1];
            }
            var date = new Date();
            if(date.getMonth()<9){
                if((date.getMonth()+1)==1||(date.getMonth()+1)==3||(date.getMonth()+1)==5||(date.getMonth()+1)==7||(date.getMonth()+1)==8){
                    if(date.getDate()<=9){
                        var resDate = date.getFullYear()+"-0"+(date.getMonth()+1)+"-0"+(date.getDate()+1);
                    }else if(date.getDate()==31){
                        var resDate = date.getFullYear()+"-0"+(date.getMonth()+2)+"-0"+1;
                    }else{
                        var resDate = date.getFullYear()+"-0"+(date.getMonth()+1)+"-"+(date.getDate()+1);
                    }
                }else if((date.getMonth()+1)==4||(date.getMonth()+1)==6||(date.getMonth()+1)==9){
                    if(date.getDate()<=9){
                        var resDate = date.getFullYear()+"-0"+(date.getMonth()+1)+"-0"+(date.getDate()+1);
                    }else if(date.getDate()==30){
                        var resDate = date.getFullYear()+"-0"+(date.getMonth()+2)+"-0"+1;
                    }else{
                        var resDate = date.getFullYear()+"-0"+(date.getMonth()+1)+"-"+(date.getDate()+1);
                    }
                }else if((date.getMonth()+1)==2){
                    if(date.getDate()<=9){
                        var resDate = date.getFullYear()+"-0"+(date.getMonth()+1)+"-0"+(date.getDate()+1);
                    }else if(date.getDate()==28){
                        var resDate = date.getFullYear()+"-0"+(date.getMonth()+2)+"-0"+1;
                    }else if(date.getDate()==29){
                        var resDate = date.getFullYear()+"-0"+(date.getMonth()+2)+"-0"+1;
                    }else{
                        var resDate = date.getFullYear()+"-0"+(date.getMonth()+1)+"-"+(date.getDate()+1);
                    }
                }

            }else{
                if((date.getMonth()+1)==10){
                    if(date.getDate()<=9){
                        var resDate = date.getFullYear()+"-0"+(date.getMonth()+1)+"-0"+(date.getDate()+1);
                    }else if(date.getDate()==31){
                        var resDate = date.getFullYear()+(date.getMonth()+2)+"-0"+1;
                    }else{
                        var resDate = date.getFullYear()+(date.getMonth()+1)+"-"+(date.getDate()+1);
                    }
                }else if((date.getMonth()+1)==11){
                    if(date.getDate()<=9){
                        var resDate = date.getFullYear()+"-0"+(date.getMonth()+1)+"-0"+(date.getDate()+1);
                    }else if(date.getDate()==30){
                        var resDate = date.getFullYear()+(date.getMonth()+2)+"-0"+1;
                    }else{
                        var resDate = date.getFullYear()+(date.getMonth()+1)+"-"+(date.getDate()+1);
                    }
                }else if((date.getMonth()+1)==12){
                    if(date.getDate()<=9){
                        var resDate = date.getFullYear()+"-0"+(date.getMonth()+1)+"-0"+(date.getDate()+1);
                    }else if(date.getDate()==30){
                        var resDate = (date.getFullYear()+1)+"-0"+1+"-0"+1;
                    }else{
                        var resDate = date.getFullYear()+(date.getMonth()+1)+"-"+(date.getDate()+1);
                    }
                }
            }
            console.log(resDate)
            $("#mydate").attr("min",resDate);
            var vue = new Vue({
                el:'#app',
                data:{
                    url:'http://localhost:8889',
                    param:{classsess:0,isCoach:0},
                    classinfo:{coaId:0,classSess:0},
                    coachs:[],
                    coach:{}
                },

                methods:{
                    getClassInfo:function(){
                        var that = this;
                        if(classId>0){
                            $.getJSON(that.url+"/class/find/"+classId,function(data){
                                that.classinfo = data;
                                console.log(that.classinfo)
                                if(that.classinfo.coach.coaId>0){
                                    that.classinfo.coaId = that.classinfo.coach.coaId;
                                    console.log( that.classinfo.coaId)
                                }
                                if(that.classinfo.classSess == '上午场'){
                                    that.param.classsess =1
                                    console.log(that.param.classsess)
                                }else if(that.classinfo.classSess == '下午场'){
                                    that.param.classsess =2
                                    console.log(that.param.classsess)
                                }
                            });
                        }
                    },
                    getCoachs:function() {
                        var that = this;
                        var loginCoaId = localStorage.getItem("role_id")
                        if(loginCoaId>0){
                            $.getJSON(that.url + "/coach/find/"+loginCoaId, function (data) {
                                that.coach = data;
                                that.param.isCoach = 1
                                console.log(that.param.isCoach )
                            })
                        }else{
                            $.getJSON(that.url + "/coach/findAll", function (data) {
                                that.coachs = data;
                                that.param.isCoach = 0
                                console.log(that.param.isCoach )
                            })
                        }

                    },
                    save:function() {
                        var that = this;
                        if(that.param.classsess ==1){
                            that.classinfo.classSess = '上午场'
                        }else if(that.param.classsess ==2){
                            that.classinfo.classSess = '下午场'
                        }
                        if(that.param.isCoach ==1){
                            var ps = {
                                classId:that.classinfo.classId,
                                coaId : localStorage.getItem("role_id"),
                                teaTime:$("#mydate").val(),
                                classSess:that.classinfo.classSess,
                                classHour:that.classinfo.classHour,
                                status:1,
                                remark:that.classinfo.remark

                            }
                        }else{
                            var ps = {
                                classId:that.classinfo.classId,
                                coaId : that.classinfo.coaId,
                                teaTime:$("#mydate").val(),
                                classSess:that.classinfo.classSess,
                                classHour:that.classinfo.classHour,
                                status:1,
                                remark:that.classinfo.remark

                            }
                        }

                        console.log(ps)
                            if((ps.coaId==null)||(ps.teaTime==null)||(ps.classSess==null)||(ps.classHour==null)){
                                $("#msg").html("<span style='color:red'>请完善课程信息</span>");
                            }else{
                                var info ={
                                    coaId:that.classinfo.coaId,
                                    teaTime:$("#mydate").val(),
                                    classSess:that.classinfo.classSess
                                }
                                $.post(that.url+'/class/queryClass',info,function(data){
                                    if(data){
                                        $("#msg").html("<span style='color:darkgreen'>该教练已经安排了今天的课程！</span>");
                                    }else{
                                        $.post(that.url+'/class/save',ps,function (data) {
                                            if(data !=null) {
                                                $("#msg").html("<span style='color:darkgreen'>课程信息保存成功！</span>");
                                                console.log(ps);
                                            }else{
                                                console.log(ps);
                                            }
                                        })
                                    }
                                })

                            }
                    },
                    hchange:function(){
                        var that = this;
                        if(that.param.classsess ==1){
                             that.classinfo.classHour =2
                        }else if(that.param.classsess ==2){
                             that.classinfo.classHour =3
                        }
                    }
                }
            });
            vue.getClassInfo();
            vue.getCoachs();
            $("#header").load("header.html");
            $("#left").load("left.html");

/**
            $("#date").datepicker({
                autoclose:true,
                language:'zh-CN',
                format:'yyyy-mm-dd',
                todayBtn:"linked",
                todayHighlight:true,
            });*/


        })
    </script>
    <style>
        .input-group-addon{
            background: #fff}
        .mrow{
            margin-top:15px;padding:5px 15px;}
        .msg{
            padding-top:10px;font-size:16px;font-weight: bold}
        .bg {
            background:url(images/subject/bg2.jpg) no-repeat center fixed;
            background-size:100%;
        }
        .bgcon{

            background: white;
            opacity:0.9;
        }
        .jllb{

            margin-left:10px;
            margin-top:10px;
            margin-bottom:10px;
        }
        .remark{
            margin-bottom: 20px;
            margin-right: 10px;
            color: #737373;
        }
        .tithead{
            margin-left:5px;
            margin-bottom: 30px;
        }
        .read{
            background:#fff !important;
        }

    </style>
</head>
<body>
<div class="container-fluid bgcon" id="app">
    <div class="row" id="header">

    </div>
    <div class="row">
        <div class="col-md-2" id="left">

        </div>
        <div class="col-md-7" style="margin-left:30px;margin-top:10px">
            <div class="row tithead">

                <div class="col-md-4"><h3 class="glyphicon glyphicon-road"> 课程信息管理
                </h3></div>
                <div class="col-md-6"></div>

                <div class="col-md-2" style="margin-top:20px">
                    <h4>
                        <a href="classinfoes.html" style="text-decoration:none;color: #666666">
                            课程信息列表 <i class="glyphicon glyphicon-chevron-right"></i>
                        </a>
                    </h4>
                </div>

            </div>
            <div class="row">
                <div class="col-md-12">
                    <div>

                        <!-- Nav tabs -->
                        <ul class="nav nav-tabs" role="tablist">
                            <li role="presentation" class="active">
                                <a href="#coa" aria-controls="coa" role="tab" data-toggle="tab">课程基本信息</a>
                            </li>
                        </ul>

                        <!-- Tab panes -->

                        <div class="tab-content">
                            <div role="tabpanel" class="tab-pane active" id="coa">
                                <div v-if="param.isCoach===0" class="form-group mrow">

                                    <div class="input-group">
                                        <label class="input-group-addon">教练姓名</label>
                                        <select v-model="classinfo.coaId" class="form-control"  placeholder="请输入教练姓名">
                                        <option value="0">请选择教练</option>
                                        <option   v-for="c in coachs" :value="c.coaId">{{c.coaName}}</option>
                                        </select>

                                    </div>

                                </div>
                                <div   v-else-if="param.isCoach===1" class="form-group mrow">

                                    <div class="input-group">
                                        <label class="input-group-addon">教练姓名</label>
                                        <input v-model="coach.coaName" class="form-control">
                                    </div>

                                </div>

                                <div class="form-group mrow">
                                    <div class="input-group">
                                        <label class="input-group-addon">课程时间</label>
                                        <!--<input v-model="classinfo.teaTime" class="form-control read" readonly id="date" placeholder="请输入时间">-->
                                        <input type="date" v-model="classinfo.teaTime" class="form-control" id="mydate">
                                    </div>
                                </div>
                                <div class="form-group mrow">
                                    <div class="input-group">
                                        <label class="input-group-addon">课程场次</label>
                                        <select v-model="param.classsess" class="form-control" id="sess" @change="hchange">
                                            <option value="0">请选择场次</option>
                                            <option value="1">上午场</option>
                                            <option value="2">下午场</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="form-group mrow">
                                    <div class="input-group">
                                        <label class="input-group-addon">课时数</label>
                                        <input v-model="classinfo.classHour" class="form-control" placeholder="请输入课时" id="hour" readonly>
                                        <label class="input-group-addon">小时</label>
                                    </div>
                                </div>
                                <div class="form-group mrow">
                                    <div class="input-group">
                                        <label class="input-group-addon">备注信息</label>
                                        <input v-model="classinfo.remark" class="form-control"  placeholder="请输入备注信息">
                                    </div>
                                </div>


                                <div class="row mrow">



                                    <div class="col-md-10">
                                        <p class="text-center msg" id="msg"></p>
                                    </div>
                                    <div class="col-md-2">
                                        <button @click="save" class="btn btn-primary btn-block">保存</button>
                                    </div>
                                </div>
                            </div>

                        </div>
                    </div>
                </div>
            </div>
            <div class="row text-right remark"><h5>备注：课程详细信息录入</h5></div>
        </div>
    </div>
</div>
</body>
</html>